package com.aq.lambda;



public class TestLambda1 {

    //2.静态内部类
    static class Like2 implements ILike{
        @Override
        public void lambda() {
            System.out.println("I like lambda2");
        }
    }

    public static void main(String[] args) {
        ILike like1 = new Like1();
        like1.lambda();
        ((Like1) like1).zi(); //转了之后可以使用

        like1 = new Like2();
        like1.lambda();

        //3.局部内部类
        class Like3 implements ILike{
            @Override
            public void lambda() {
                System.out.println("I like lambda3");
            }
        }
        like1 = new Like3();
        like1.lambda();

        //4.匿名内部类，没有类的名称，必须借助接口或者父类
        like1 = new ILike() {
            @Override
            public void lambda() {
                System.out.println("I like lambda4");
            }
        };
        like1.lambda();

        // 5.用Lambda简化
        like1 = () -> {
            System.out.println("I Like Lambda5");
        };
        like1.lambda();


    }
}

//定义一个函数接口
interface ILike{
    void lambda();
}

//1.实现类
class Like1 implements ILike{
    @Override
    public void lambda() {
        System.out.println("I like lambda");
    }
    public void zi(){
        System.out.println("子类特有的方法，new一个父类指向子类时使用不了");
    }
}